import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

// import { h } from 'vue';
import { DictEnum } from '@vben/constants';
// import { VbenIcon } from '@vben/icons';
import { getPopupContainer } from '@vben/utils';

// import { Tag } from 'ant-design-vue';
// import { z } from '#/adapter/form';
import { SensitiveText } from '#/components/text';
import { getDictOptions } from '#/utils/dict';
import { renderDict } from '#/utils/render';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'name',
    label: '姓名',
  },
  {
    component: 'CompanySearchSelect',
    fieldName: 'companyId',
    label: '公司',
  },
  {
    component: 'Select',
    fieldName: 'departmentIds',
    label: '部门',
    componentProps: {
      mode: 'multiple',
      getPopupContainer,
      options: getDictOptions(DictEnum.AUDIENCE_DEPARTMENT, true),
    },
  },
  {
    component: 'Select',
    fieldName: 'positionIds',
    label: '职位',
    componentProps: {
      mode: 'multiple',
      getPopupContainer,
      options: getDictOptions(DictEnum.AUDIENCE_POSITION, true),
    },
  },
  {
    component: 'Input',
    fieldName: 'mobile',
    label: '手机号',
  },
  {
    component: 'Input',
    fieldName: 'email',
    label: '邮箱',
  },
  {
    component: 'Select',
    fieldName: 'number',
    label: '届数',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.EXHIBITION_NUMBER, true),
    },
    defaultValue: 27,
  },
  {
    component: 'RegisterTrackCascader',
    fieldName: 'sourceTrackIds',
    componentProps: {
      multiple: true,
    },
    disabledOnChangeListener: false,
    defaultValue: [],
    label: '所属来源',
  },
  {
    component: 'RangePicker',
    fieldName: 'createTime',
    label: '登记日期',
  },
  {
    component: 'Select',
    fieldName: 'sitStatus',
    label: '到场状态',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.REGISTER_SIT_STATUS, true),
    },
  },
  {
    component: 'Select',
    fieldName: 'type',
    label: '观众类别',
    componentProps: {
      getPopupContainer,
      options: getDictOptions(DictEnum.REGISTER_AUDIENCE_CATEGORY, true),
    },
  },
  // {
  //   component: 'DatePicker',
  //   fieldName: 'createTime',
  //   label: '登记日期',
  //   componentProps: {
  //     format: 'YYYY-MM-DD HH:mm:ss',
  //     showTime: true,
  //     valueFormat: 'YYYY-MM-DD HH:mm:ss',
  //     getPopupContainer,
  //   },
  // },
];

export const columns: VxeGridProps['columns'] = [
  { type: 'checkbox', width: 60 },
  {
    title: '姓名',
    field: 'name',
    width: 160,
    slots: { default: 'name' },
  },
  {
    title: '公司',
    field: 'companyName',
    width: 240,
    slots: { default: 'companyName' },
  },
  {
    title: '届数',
    field: 'number',
    width: 80,
    slots: {
      default: ({ row }) => {
        return renderDict(row.number, DictEnum.EXHIBITION_NUMBER);
      },
    },
  },
  {
    title: '手机',
    field: 'mobile',
    width: 160,
    slots: {
      default: ({ row }) => {
        return (
          <SensitiveText
            access-page={3}
            employee-id={row.employeeId}
            text={row.mobile}
            type={1}
          />
        );
      },
    },
  },
  {
    title: '邮箱',
    field: 'email',
    width: 230,
    slots: {
      default: ({ row }) => {
        return (
          <SensitiveText
            access-page={3}
            employee-id={row.employeeId}
            text={row.email}
            type={2}
          />
        );
      },
    },
  },
  {
    title: '部门',
    field: 'departmentId',
    width: 160,
    slots: {
      default: ({ row }) => {
        return renderDict(row.departmentId, DictEnum.AUDIENCE_DEPARTMENT);
      },
    },
  },
  {
    title: '职位',
    field: 'positionId',
    width: 160,
    slots: {
      default: ({ row }) => {
        return renderDict(row.positionId, DictEnum.AUDIENCE_POSITION);
      },
    },
  },
  {
    title: '所在地区',
    field: 'countryCode',
    width: 200,
    slots: {
      default: ({ row }) => {
        if (row?.countryCode !== '00') {
          return <span>{row.countryCode}</span>;
        }

        if (row?.cityName) {
          return (
            <span>
              {row.provinceName}
              {row.cityName}
            </span>
          );
        }

        return <span>{row?.provinceName}</span>;
      },
    },
  },
  {
    title: '所属来源',
    field: 'sourceTrackName',
    width: 380,
    showOverflow: true,
  },
  {
    title: '创建时间',
    field: 'createTime',
    width: 180,
  },
  {
    title: '观众类别',
    field: 'type',
    width: 120,
    slots: {
      default: ({ row }) => {
        return renderDict(row.type, DictEnum.REGISTER_AUDIENCE_CATEGORY, true);
      },
    },
    titlePrefix: {
      content:
        '此字段保存观众的初始登记来源（专业/团体），不会随后续变更而改变。',
    },
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    width: 'auto',
  },
];

export const detailsSchema: DetailsModalSchemaGetter = () => [
  {
    label: '姓名',
    fieldName: 'name',
    copy: true,
  },
  {
    label: '公司',
    fieldName: 'companyName',
    copy: true,
  },
  {
    label: '届数',
    fieldName: 'number',
    dictEnum: DictEnum.EXHIBITION_NUMBER,
  },
  {
    label: '手机号',
    fieldName: 'mobile',
    slots: {
      default: (info) => {
        return (
          <SensitiveText
            access-page={3}
            employee-id={info.employeeId}
            text={info.mobile}
            type={1}
          />
        );
      },
    },
  },
  {
    label: '邮箱',
    fieldName: 'email',
    slots: {
      default: (info) => {
        return (
          <SensitiveText
            access-page={3}
            employee-id={info.employeeId}
            text={info.email}
            type={2}
          />
        );
      },
    },
  },
  {
    label: '部门',
    fieldName: 'departmentId',
    dictEnum: DictEnum.AUDIENCE_DEPARTMENT,
  },
  {
    label: '职位',
    fieldName: 'positionId',
    dictEnum: DictEnum.AUDIENCE_POSITION,
  },
  {
    label: '所在地区',
    fieldName: 'countryCode',
    span: 2,
    copy: (info: any) => {
      if (info.countryCode !== '00') {
        return `${info.address} ${info.countryName}`;
      }

      return `${info.countryName}${info.provinceName}${info.cityName}${info.districtName}${info.address}`;
    },
    slots: {
      default: (info) => {
        if (info.countryCode !== '00') {
          return (
            <span>
              {info.address} {info.countryName}
            </span>
          );
        }
        return (
          <span>
            {info.countryName}
            {info.provinceName}
            {info.cityName}
            {info.districtName}
            {info.address}
          </span>
        );
      },
    },
  },
  {
    label: '所属来源',
    fieldName: 'sourceTrackName',
    copy: true,
  },
  {
    label: '备注',
    fieldName: 'remark',
  },
];
